package com.sunwayhorizo.health.hl7.rim;

import com.sunwayhorizo.health.hl7.common.DataTypeUtil;
import static com.sunwayhorizo.health.hl7.vocabulary.ActCdSetCode.CONFIDENTIALITYCDSETCODE;
import static com.sunwayhorizo.health.hl7.vocabulary.ActCdSetCode.LANGUAGECDSETCODE;
import static com.sunwayhorizo.health.hl7.vocabulary.ActCdSetCode.LEVELCDSETCODE;
import static com.sunwayhorizo.health.hl7.vocabulary.ActCdSetCode.PRIORITYCDSETCODE;
import static com.sunwayhorizo.health.hl7.vocabulary.ActCdSetCode.REASONCDSETCODE;
import static com.sunwayhorizo.health.hl7.vocabulary.ActCdSetCode.UNCERTAINTYCDSETCODE;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Transient;


import com.sunwayhorizo.health.hl7.common.Hl7Exception;
import com.sunwayhorizo.health.hl7.common.ListUtil;
import com.sunwayhorizo.health.hl7.common.StrUtil;
import com.sunwayhorizo.health.hl7.datatypes.BL;
import com.sunwayhorizo.health.hl7.datatypes.CD;
import com.sunwayhorizo.health.hl7.datatypes.CE;
import com.sunwayhorizo.health.hl7.datatypes.CS;
import com.sunwayhorizo.health.hl7.datatypes.ED;
import com.sunwayhorizo.health.hl7.datatypes.GTS;
import com.sunwayhorizo.health.hl7.datatypes.II;
import com.sunwayhorizo.health.hl7.datatypes.IVL_INT;
import com.sunwayhorizo.health.hl7.datatypes.PQ;
import com.sunwayhorizo.health.hl7.datatypes.SET_CE;
import com.sunwayhorizo.health.hl7.datatypes.SET_II;
import com.sunwayhorizo.health.hl7.datatypes.ST;
import com.sunwayhorizo.health.hl7.datatypes.TS;
import com.sunwayhorizo.health.hl7.persistent.RimCoreActCdSets;
import com.sunwayhorizo.health.hl7.persistent.RimCoreActIi;
import com.sunwayhorizo.health.hl7.persistent.RimCoreActPrtcptns;
import com.sunwayhorizo.health.hl7.persistent.RimCoreActRelations;
import com.sunwayhorizo.health.hl7.persistent.RimCoreActs;
import com.sunwayhorizo.health.hl7.persistent.RimCoreEds;
import com.sunwayhorizo.health.hl7.vocabulary.ActCdSetCode;
import com.sunwayhorizo.health.hl7.vocabulary.ActIICode;

/**
 * @ClassName Act <br>
 * @PackageName com.sunwayhorizo.health.hl7.rim <br>
 * @Description 行为<br>
 * @Author xuyx <br>
 * @Date 2011-5-14 <br>
 * @Version 1.0 <br>
 * @ModifiedDesc <br>
 * @ModifiedDate <br>
 * @ModifiedBy <br>
 * @Copyright 2010-2020 北京三维海容 All Rights Reserved. <br>
 */

@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorValue("ACT")
@AttributeOverrides({ @AttributeOverride(name = "activityDateGtsTxt", column = @Column(name = "ACTIVITY_DATE_GTS_TXT")),
        @AttributeOverride(name = "activityEndDateTs", column = @Column(name = "ACTIVITY_END_DATE_TS")),
        @AttributeOverride(name = "activityStartDateTs", column = @Column(name = "ACTIVITY_START_DATE_TS")) })
public class Act extends RimCoreActs implements Serializable
{

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    /**
     * 动作活跃时间区间，管理上使用，区间大于effectiveTime。
     */
    @Transient
    public GTS activityTime;

    /**
     * 信息进入系统时间点(发送或接收的时间)，通常为信息登记时间。
     */
    @Transient
    public TS availabilityTime;

    /*
     * public CS classCode;//动作类的代码，是类的名称的缩写 public CD
     * code;//动作代码例如身体检查，血清钾，病人门诊，财务处理等等。
     */

    /**
     * 行为执行时间点。
     */
    @Transient
    public ST excuteTime;

    /**
     * 行为可持续时间。
     */
    @Transient
    public PQ durationTIme;

    /**
     * 行为机密性级别，可用于数据权限管理。
     */
    @Transient
    public SET_CE confidentialityCode;
    /**
     * 推导表达式，用于描述计算公式。
     */
    @Transient
    public ST derivationExpr;
    /**
     * 动作有效时间区间，医疗上使用，例如医嘱TID for 10 days。
     */
    @Transient
    public GTS effectiveTime;
    /**
     * 行为的唯一标识符，详见HL7 II 概念。
     */
    @Transient
    public SET_II id;
    /**
     * 行为A（TARGET）与行为B（SOURCE）内联.
     */
    @Transient
    public Iterator iBActRelationships;
    /**
     * 行为独立(是否独立)，不依赖其它行为，布尔型，缺省值为ture。
     */
    @Transient
    public BL independentInd;
    /**
     * 行为可否被异步事件中断属性，布尔型。
     */
    @Transient
    public BL interruptibleInd;
    /**
     * text文本的语言种类，例如中文、英文。
     */
    @Transient
    public CE languageCode;
    /**
     * 级别代码属性，用于行为分类层级。
     */
    @Transient
    public CE levelCode;
    /**
     * 行为流程状态，例如检查检验申请、预约、处理等状态；预约挂号、挂号、就诊。参考资料HL7 ACT moodCode 属性。
     */
    @Transient
    public CS moodCode;
    /**
     * 行为否定指示项。
     */
    @Transient
    public BL negationInd;
    /**
     * 行为A（SOURCE）与行为B（TARGET）外联。
     */
    @Transient
    public Iterator oBActRelationships;
    /**
     * 角色A参与到行为B中。
     */
    @Transient
    public Iterator participations;
    /**
     * 行为优先权。
     */
    @Transient
    public SET_CE priorityCode;
    /**
     * 行为原因代码。
     */
    @Transient
    public SET_CE reasonCode;
    /**
     * 行为长期、临时标志。
     */
    @Transient
    public BL repeatInd;

    /**
     * 行为重复次数。
     */
    @Transient
    public IVL_INT repeatNumber;
    /**
     * 行为重复次数单位，例如 天、周等。
     */
    @Transient
    public PQ freqInterval;
    /**
     * 行为状态代码。
     */
    @Transient
    public CS statusCode;
    /**
     * 行为标题。
     */
    @Transient
    public ST title;
    /**
     * 行为的不确定因素。
     */
    @Transient
    public CE uncertaintyCode;
    /**
     * 行为的描述，文本、图像、语音、流媒体等。
     */
    @Transient
    public ED text;//


    public Act() throws Hl7Exception
    {
        DataTypeUtil.initialize();
    }




    /**
     * 设置动作活跃时间区间
     */
    public void setActivityTime(GTS activityTime)
    {
        this.setActivityStartDateTs(new Timestamp(activityTime.hull().low().toDate().getTime()));
        this.setActivityEndDateTs(new Timestamp(activityTime.hull().high().toDate().getTime()));
        this.setActivityDateGtsTxt(activityTime.literal().toString());
    }


    /**
     * 获得动作活跃时间区间
     */
    public GTS getActivityTime() throws Hl7Exception
    {
        if (getActivityStartDateTs() != null && getActivityStartDateTs() != null)
        {
            return DataTypeUtil.getGTS(DataTypeUtil.getIVL_TS(new Date(this.getActivityStartDateTs().getTime()), new Date(this.getActivityEndDateTs()
                .getTime())));
        }
        else
        {
            return null;
        }
    }


    /**
     * 设置进入系统时间点
     * 
     * @param availabilityTime
     *            进入系统时间点
     * @throws Hl7Exception
     */
    public void setAvailabilityTime(TS availabilityTime)
    {
        this.setAvailablityDateTs(new Timestamp(availabilityTime.toDate().getTime()));
        this.setAvailableDateTxt(availabilityTime.literal().toString());
    }


    /**
     * 获得进入系统时间点
     * 
     * @return TS availabilityTime
     * @throws Hl7Exception
     */
    public TS getAvailabilityTime() throws Hl7Exception
    {
        return DataTypeUtil.getTS(new Date(this.getAvailablityDateTs().getTime()));
    }


    /**
     * 行为执行时间点
     * 
     * @return ST ExcuteTime
     * @throws Hl7Exception
     */
    public ST getExcuteTime() throws Hl7Exception
    {
        return DataTypeUtil.getST(this.getExcuteTimeTxt());
    }


    public void setExcuteTime(ST excuteTime)
    {
        if(excuteTime == null) return;
        this.setExcuteTimeTxt(excuteTime.toString());
    }


    /**
     * 行为持续时间
     * 
     * @return ST DurationTime
     * @throws Hl7Exception
     */
    public PQ getDurationTIme() throws Hl7Exception
    {
        return DataTypeUtil.getPQ((StrUtil.isEmpty(this.getDurationTimeTxt()) ? "" : this.getDurationTimeTxt()),
            (StrUtil.isEmpty(this.getDurationTimeUnit()) ? "" : this.getDurationTimeUnit()));
    }


    @SuppressWarnings("null")
    public void setDurationTime(PQ durationTime)
    {
        if (durationTime == null || durationTime.isNull().isTrue())
            return;
        this.setDurationTimeTxt(durationTime.value().toString());
        this.setDurationTimeUnit(durationTime.unit().toString());
    }


    /**
     * 设置推导表达式
     */
    public void setDerivationExpr(ST derivationExpr)
    {
        this.setDerivationExpressionTxt(derivationExpr.toString());
    }


    /**
     * 获取推导表达式
     */
    public ST getDerivationExpr() throws Hl7Exception
    {
        return DataTypeUtil.getST(this.getDerivationExpressionTxt());
    }


    /**
     * 设置行为有效时间区间，医疗上使用，例如医嘱TID for 10 days。
     */
    public void setEffectiveTime(GTS effectiveTime)
    {
        if (effectiveTime != null && effectiveTime.isNull().isFalse())
        {
            if(effectiveTime.hull().low() != null)
            {
                this.setEffectiveStartDateTs(new Timestamp(effectiveTime.hull().low().toDate().getTime()));
            }
            else
            {
                this.setEffectiveStartDateTs(null); 
            }
            
            if(effectiveTime.hull().high() != null)
            {
                this.setEffectiveEndDateTs(new Timestamp(effectiveTime.hull().high().toDate().getTime())); 
            }
            else
            {
                this.setEffectiveEndDateTs(null); 
            }
           
            this.setEffectiveDateGtsTxt(effectiveTime.literal().toString()); 
        }
        else
        {
            this.setEffectiveStartDateTs(null); 
            this.setEffectiveEndDateTs(null); 
            this.setEffectiveDateGtsTxt(null);
        }
        
    }


    /**
     * 获取行为有效时间区间，医疗上使用，例如医嘱TID for 10 days。
     */
    public GTS getEffectiveTime() throws Hl7Exception
    {
        return DataTypeUtil.getGTS(DataTypeUtil.getIVL_TS(new Date((this.getEffectiveStartDateTs() == null ? 0 : this.getEffectiveStartDateTs()
            .getTime())), new Date((this.getEffectiveEndDateTs() == null ? 0 : this.getEffectiveEndDateTs().getTime()))));
    }


    /**
     * 得到行为的唯一性id
     * 
     * @param identifierName
     *            唯一性值的区别字段
     * @return II
     * @throws Hl7Exception
     */
    public II getId(ActIICode identifierName) throws Hl7Exception
    {
        if (identifierName == null)
        {
            return null;
        }
        for (RimCoreActIi ii : getActsIiList())
        {
            if (identifierName.toString().equals(ii.getIdentifierName()))
            {
                return DataTypeUtil.getII(ii.getRootId(), ii.getExtensionTxt(), ii.getDisplayableFlag(), ii.getIdentifierName(), ii.getClinicNo());
            }
        }
        return null;
    }


    /**
     * 设置行为的id
     * 
     * @param id
     *            唯一性值
     */
    public void setId(II id)
    {
        for (RimCoreActIi ii : getActsIiList())
        {
            if (ii.getIdentifierName().equals(id.identifierName().toString()))
            {
                convertRimCoreActIi(ii, id);
                ii.setRimCoreActCdSets(convertRimCoreActCdSets(ii.getRimCoreActCdSets(), id.iiType()));
                ii.setLastUpdatedBy(getLastUpdatedBy());
                ii.setLastUpdateDate(new Timestamp(new Date().getTime()));
                return;
            }
        }
        // 都不匹配identifierName新建ActIi
        RimCoreActIi actIi = new RimCoreActIi();

        if (id.iiType() != null && !id.iiType().isNull().booleanValue())
        {
            RimCoreActCdSets actCdSets = new RimCoreActCdSets();
            addActCdSets(actCdSets);
            actIi.setRimCoreActCdSets(convertRimCoreActCdSets(new RimCoreActCdSets(), id.iiType()));
        }
        actIi.setCreatedBy(getCreatedBy());
        actIi.setCreationDate(new Timestamp(new Date().getTime()));
        actIi.setLastUpdateDate(new Timestamp(new Date().getTime()));
        actIi.setLastUpdatedBy(getLastUpdatedBy());
        addActIi(convertRimCoreActIi(actIi, id));
    }


    /**
     * 设置行为是否独立，不依赖其它行为，缺省值为1-ture；0-false。
     */
    public void setIndependentInd(BL independentInd) throws Hl7Exception
    {
        if (independentInd.isTrue())
        {
            this.setIndependentFlag("1");
        }
        else if (independentInd.isFalse())
        {
            this.setIndependentFlag("0");
        }
    }


    /**
     * 获取行为是否独立属性，1-ture；0-false。
     */
    public BL getIndependentInd() throws Hl7Exception
    {
        if ("1".equals(this.getIndependentInd()))
        {
            return DataTypeUtil.getBL("true");
        }
        return DataTypeUtil.getBL("false");
    }


    /**
     * 设置行为可否被异步事件中断属性，1-ture；0-false。
     */
    public void setInterruptibleInd(BL interruptibleInd) throws Hl7Exception
    {
        if (interruptibleInd.isTrue())
        {
            this.setInterruptableFlag("1");
        }
        else if (interruptibleInd.isFalse())
        {
            this.setInterruptableFlag("0");
        }
    }


    /**
     * 获取行为可否被被异步事件中断属性，1-ture；0-false。
     */
    public BL getInterruptibleInd() throws Hl7Exception
    {
        if ("1".equals(this.getInterruptibleInd()))
        {
            return DataTypeUtil.getBL("true");
        }
        return DataTypeUtil.getBL("false");
    }


    /**
     * 设置行为流程状态
     */
    public void setMoodCode(CS moodCode)
    {
        this.setMoodCode(moodCode.code().toString());
    }


    /**
     * 获取行为流程状态
     */
    public CS getMoodCode() throws Hl7Exception
    {
        return DataTypeUtil.getCS(this.getMood_Code());
    }


    /**
     * 1 表示true 0 表示false *
     */
    public void setNegationInd(BL negationInd)
    {
        if (negationInd.isTrue())
        {
            this.setNegationFlag("1");
        }
        else if (negationInd.isFalse())
        {
            this.setNegationFlag("0");
        }
    }


    /**
     * 获取行为流程状态
     */
    public BL getNegationInd() throws Hl7Exception
    {
        if ("1".equals(this.getNegationFlag()))
        {
            return DataTypeUtil.getBL("true");
        }
        return DataTypeUtil.getBL("false");
    }


    public void addIBActRelationship(CS arType, Act source)
    {
        ActRelationship actRelationship = new ActRelationship();
        actRelationship.setTypeCode(arType);

        source.addSourceAct(actRelationship);
        this.addTargetAct(actRelationship);

        ControlAct controlAct = (ControlAct) source.getControlAct();
        if (null == controlAct)
        {
            return;
        }
        // if (controlAct == null) throw
        // InfrastructureRoot.newParameterMissingException("actRelationship");
        controlAct.addControlActAct(this);
        controlAct.addControlActRelation(actRelationship);
    }


    /**
     * 建立行为与行为之间的内连关系
     */
    public void addIBActRelWhithOutAct(CS arType, Act source)
    {
        ActRelationship actRelationship = new ActRelationship();
        actRelationship.setTypeCode(arType);

        source.addSourceAct(actRelationship);
        this.addTargetAct(actRelationship);

        ControlAct controlAct = (ControlAct) source.getControlAct();
        if (null == controlAct)
        {
            return;
        }
        controlAct.addControlActRelation(actRelationship);
    }


    /**
     * 根据内联类型获取指定行为Act
     */
    public Act getIBActRelByTypeCode(CS arType) throws Hl7Exception
    {
        List<RimCoreActRelations> relations = (List<RimCoreActRelations>) this.getTargetActRelationsList();
        for (RimCoreActRelations relation : relations)
        {
            if (arType.code().toString().equals(((ActRelationship) relation).getTypeCode().code().toString()))
            {
                return (Act) relation.getSourceAct();
            }
        }
        return null;
    }


    /**
     * 获取具有内连关系的所有行为Act
     */
    @SuppressWarnings({ "unchecked" })
    public List<Act> getIBActRelationships()
    {
        List<Act> result = new ArrayList<Act>();
        List<RimCoreActRelations> relations = (List<RimCoreActRelations>) this.getTargetActRelationsList();
        for (RimCoreActRelations relation : relations)
        {
            Act act = (Act) relation.getSourceAct();
            result.add(act);
        }
        if (ListUtil.isNotEmpty(result))
        {
            return result;
        }
        return null;
    }


    /**
     * 根据目标动作查找源动作
     * 
     * @param actClass
     *            源动作classCode
     * @param actCode
     *            源动作Code
     * @return Act 源动作
     * @throws Hl7Exception
     */
    public Act getSourceActByTargetAct(CS actClass, CD actCode) throws Hl7Exception
    {
        List<Act> acts = this.getIBActRelationships();
        if (ListUtil.isNotEmpty(acts))
        {
            for (Act sourceAct : acts)
            {
                if (sourceAct.getClassCode().equals(actClass) && sourceAct.getCode().code().toString().equals(actCode.code().toString()))
                {
                    return sourceAct;
                }
            }
        }
        return null;
    }


    /**
     * 根据目标动作查找源动作集合
     * 
     * @param actClass
     *            源动作classCode
     * @param actCode
     *            源动作Code
     * @return List<? extends Act> 源动作集合
     * @throws Hl7Exception
     */
    public List<? extends Act> getSourceActListByTargetAct(CS actClass, CD actCode) throws Hl7Exception
    {
        List<Act> sourceActList = new ArrayList<Act>();
        List<Act> acts = this.getIBActRelationships();
        if (ListUtil.isNotEmpty(acts))
        {
            for (Act sourceAct : acts)
            {
                if (sourceAct != null && sourceAct.getClassCode().equals(actClass)
                        && sourceAct.getCode().code().toString().equals(actCode.code().toString()))
                {
                    sourceActList.add(sourceAct);
                }
            }
        }
        return sourceActList;
    }


    /**
     * 根据源动作得到目标动作
     * 
     * @param actClass
     *            目标动作ActClass
     * @param actCode
     *            目标动作Code
     * @return Act 目标动作
     * @throws Hl7Exception
     */
    public Act getTargetActBySourceAct(CS actClass, CD actCode) throws Hl7Exception
    {
        List<Act> acts = this.getOBActRelationships();
        if (ListUtil.isNotEmpty(acts))
        {
            for (Act targetAct : acts)
            {
                if (targetAct.getClassCode().equals(actClass) && targetAct.getCode().code().toString().equals(actCode.code().toString()))
                {
                    return targetAct;
                }
            }
        }
        return null;
    }


    /**
     * 根据源动作得到目标动作集合
     * 
     * @param actClass
     *            目标动作ActClass
     * @param actCode
     *            目标动作Code
     * @return List<? extends Act> 目标动作集合
     * @throws Hl7Exception
     */
    public List<? extends Act> getTargetActListBySourceAct(CS actClass, CD actCode) throws Hl7Exception
    {
        List<Act> targetActList = new ArrayList<Act>();
        List<Act> acts = this.getOBActRelationships();
        if (ListUtil.isNotEmpty(acts))
        {
            for (Act targetAct : acts)
            {
                if (targetAct != null && targetAct.getClassCode().equals(actClass) && targetAct.getCode().code().toString().equals(actCode.code().toString()))
                {
                    targetActList.add(targetAct);
                }
            }
        }
        return targetActList;
    }


    // ControlAct控制ACT的关系
    public void addOBActRelationship(CS arType, Act target)
    {

        ActRelationship actRelationship = new ActRelationship();
        actRelationship.setTypeCode(arType);

        actRelationship.setTargetAct(target);
        actRelationship.setSourceAct(this);

        if (this.getClass().getName().equals("com.sunwayhorizo.health.hl7.rim.ControlAct"))
        {
            this.addControlActAct(this);
        }

        ControlAct controlAct = (ControlAct) this.getControlAct();
        if (null == controlAct)
        {
            return;
        }
        // if (controlAct == null) throw
        // InfrastructureRoot.newParameterMissingException("actRelationship");
        controlAct.addControlActRelation(actRelationship);
        controlAct.addControlActAct(target);
        this.setControlAct(controlAct);
        target.setControlAct(controlAct);
        actRelationship.setControlAct(controlAct);
    }


    public void addIBActRelationship(ActRelationship actRelationship, Act source)
    {

        actRelationship.setSourceAct(source);
        actRelationship.setTargetAct(this);

        ControlAct controlAct = (ControlAct) this.getControlAct();
        if (null == controlAct)
        {
            return;
        }

        controlAct.addControlActRelation(actRelationship);

        if (!controlAct.getControlActActsList().contains(source) && source.getControlAct() == null)
        {

            controlAct.addControlActAct(source);
        }
        // controlAct.addControlActAct(source);
    }


    public void addOBActRelationship(ActRelationship actRelationship, Act target)
    {

        actRelationship.setSourceAct(this);
        actRelationship.setTargetAct(target);

        ControlAct controlAct = (ControlAct) this.getControlAct();
        if (null == controlAct)
        {
            return;
        }
        controlAct.addControlActRelation(actRelationship);

        if (!controlAct.getControlActActsList().contains(target) && target.getControlAct() == null)
        {

            controlAct.addControlActAct(target);
        }

    }


    public void addOBActRelWhithOutControlAct(CS arType, Act target)
    {
        ActRelationship actRelationship = new ActRelationship();
        actRelationship.setTypeCode(arType);

        target.addTargetAct(actRelationship);
        this.addSourceAct(actRelationship);
    }


    public void addOBActRelWhithOutAct(CS arType, Act target)
    {
        ActRelationship actRelationship = new ActRelationship();
        actRelationship.setTypeCode(arType);

        target.addTargetAct(actRelationship);
        this.addSourceAct(actRelationship);

        ControlAct controlAct = (ControlAct) this.getControlAct();
        if (null == controlAct)
        {
            return;
        }
        controlAct.addControlActRelation(actRelationship);
    }


    /**
     * 获取具有外联关系的所有行为Act
     */
    public List<Act> getOBActRelationships()
    {
        List<Act> result = new ArrayList<Act>();
        List<ActRelationship> relations = (List<ActRelationship>) this.getSourceActRelationsList();
        for (ActRelationship relation : relations)
        {
            Act act = (Act) relation.getTargetAct();
            result.add(act);
        }
        if (ListUtil.isNotEmpty(result))
        {
            return result;
        }
        return null;
    }


    /**
     * 根据外联类型获取所有行为Act
     */
    public Act getOBActRelByTypeCode(CS arType) throws Hl7Exception
    {
        List<RimCoreActRelations> relations = (List<RimCoreActRelations>) this.getSourceActRelationsList();
        for (RimCoreActRelations relation : relations)
        {
            if (arType.code().toString().equals(((ActRelationship) relation).getTypeCode().code().toString()))
            {
                return (Act) relation.getTargetAct();
            }
        }
        return null;
    }


    /**
     * 废弃 在Role以partType参与到Act里。
     */
    public void addPartWithOutEntRole(CS partType, Role target)
    {
        ActParticipation actParticipation = new ActParticipation();
        actParticipation.setTypeCode(partType);
        this.addPrtcptnsAct(actParticipation);
        target.addRolePrtcptns(actParticipation);

        // ControlAct controlAct = (ControlAct) this.getControlAct();
        // controlAct.addControlActPrtcptns(actParticipation);
    }


    /**
     * 角色参与到行为中。
     * 
     * @param partType
     * @param target
     */
    public void addParticipation(CS partType, Role target)
    {
        ActParticipation actParticipation = new ActParticipation();
        actParticipation.setTypeCode(partType);
        this.addPrtcptnsAct(actParticipation);
        target.addRolePrtcptns(actParticipation);

        ControlAct controlAct = (ControlAct) this.getControlAct();
        if (null == controlAct)
            return;
        controlAct.addControlActRole(target);
        controlAct.addControlActPrtcptns(actParticipation);

        controlAct.addEntity(target.getPlayerEntity());
        if (target.getScoperEntity() != null)
            controlAct.addEntity(target.getScoperEntity());

    }


    /**
     * 角色参与到行为中
     * 
     * @param participation
     *            外部构建的ActParticipation
     * @param target
     *            参与到新构建的role
     */
    public void addParticipation(ActParticipation participation, Role target)
    {
        participation.setRoleparticipation(target);
        participation.setParticipationAct(this);

        ControlAct controlAct = (ControlAct) this.getControlAct();
        if (null == controlAct)
        {
            return;
        }
        if (target.getControlAct() == null && !controlAct.getControlActRolesList().contains(target))
        {
            controlAct.addControlActRole(target);
        }
        controlAct.addControlActPrtcptns(participation);
        if (target.getPlayerEntity().getControlAct() == null && !controlAct.getControlActEntitiesList().contains(target.getPlayerEntity()))
        {
            controlAct.addEntity(target.getPlayerEntity());
        }
        if (target.getScoperEntity().getControlAct() == null && !controlAct.getControlActEntitiesList().contains(target.getScoperEntity()))
        {
            controlAct.addEntity(target.getScoperEntity());
        }

    }


    /**
     * 根据act拿到ActParticipation 里面ControlAct注释掉，等ControlAct全部用起来的时候在考虑
     */
    @SuppressWarnings("unchecked")
    public List<ActParticipation> getParticipations()
    {
        return (List<ActParticipation>) this.getPrtcptnsActList();

        // ControlAct controlAct = (ControlAct) this.getControlAct();
        // return (List<ActParticipation>)
        // controlAct.getControlActPrtcptnsList();
    }


    /**
     * 根据动作准确拿到角色参与动作的一个ActParticipation
     * 
     * @param typeCode
     *            关系 typeCode
     * @param roleCode
     *            参与动作的角色code
     * @return ActParticipation
     * @throws Hl7Exception
     */
    @SuppressWarnings("unchecked")
    public ActParticipation getParticipations(CS typeCode, CS roleCode) throws Hl7Exception
    {
        if (typeCode == null && roleCode == null)
            return null;
        List<ActParticipation> partList = (List<ActParticipation>) this.getPrtcptnsActList();
        if (ListUtil.isNotEmpty(partList))
        {
            for (int i = 0; i < partList.size(); i++)
            {
                ActParticipation part = (ActParticipation) partList.get(i);
                if (part.getTypecode().equals(typeCode))
                {
                    if ((part.getRoleParticipation().getCode().code().toString()).equals(roleCode.code().toString()))
                    {
                        return part;
                    }
                }
            }
        }
        return null;
    }


    /**
     * 获取行为重复标志.
     * 
     * @throws Hl7Exception
     */
    public ST getRepeatInd() throws Hl7Exception
    {
        return DataTypeUtil.getST(this.getRepeatFlag());
    }


    /**
     * 设置行为重复标志.
     */
    public void setRepeatInd(ST repeatInd)
    {
        this.setRepeatFlag(repeatInd.toString());
    }


    /**
     * 设置行为重复次数.
     */
    @SuppressWarnings("unused")
    public void setRepeatNumber(IVL_INT repeatNumber)
    {
        if (repeatNumber == null || repeatNumber.isNull().isTrue())
            return;
        this.setRepNumLowValueNum(repeatNumber.low().longValue());
        this.setRepNumLowInclFlag(repeatNumber.lowClosed().literal().toString());
        this.setRepNumHighValueNum(repeatNumber.high().longValue());
        this.setRepNumHighInclFlag(repeatNumber.highClosed().literal().toString());
        this.setRepNumIvlValueNum(new Long((repeatNumber.width() == null ? 0 : repeatNumber.width().intValue())));
    }


    /**
     * 获取行为重复次数
     */
    public IVL_INT getRepeatNumber() throws Hl7Exception
    {
        return DataTypeUtil.getIVL_INT(this.getRepNumLowValueNum(), this.getRepNumLowInclFlag(), this.getRepNumHighValueNum(),
            this.getRepNumHighInclFlag());
    }


    /**
     * 设置间隔频率-单位
     * 
     * @param freqInterval
     */
    public void setFreqInterval(PQ freqInterval)
    {
        if(freqInterval == null) return;
        this.setFreqIntervalValue(freqInterval.value().toString());
        this.setFreqIntervalUnit(freqInterval.unit().toString());
    }


    public PQ getFreqInterval() throws Hl7Exception
    {
        return DataTypeUtil.getPQ(this.getFreqIntervalValue(), this.getFreqIntervalUnit());
    }


    /**
     * 设置行为的描述，文本、图像、语音、流媒体等。
     */
    public void setText(ED text)
    {
        RimCoreEds ed = this.getRimCoreEdsTextEdId();
        converRimCoreEds(ed, text);
        this.setRimCoreEdsTextEdId(ed);
    }


    /**
     * 获取行为的描述，文本、图像、语音、流媒体等。
     */
    public ED getText() throws Hl7Exception
    {
        RimCoreEds ed = this.getRimCoreEdsTextEdId();
        if (null == ed)
        {
            return null;
        }
        return DataTypeUtil.getED((ed.getEdClob() == null ? "" : new String(ed.getEdClob())), ed.getEdBlob());
    }


    /**
     * 设置行为标题。
     */
    public void setTitle(ST title)
    {
        this.setTitleTxt(title.toString());
    }


    /**
     * 获取行为标题。
     */
    public ST getTitle() throws Hl7Exception
    {
        return DataTypeUtil.getST(this.getTitleTxt());
    }
    
    /**
     * 设置行为标题简拼。
     */
    public void setTitleYwm(ST titleYwm)
    {
        this.setTitleYwm(titleYwm.toString());
    }


    /**
     * 获取行为标题简拼。
     */
    public ST getTitleYWM() throws Hl7Exception
    {
        return DataTypeUtil.getST(this.getTitleYwm());
    }


    /**
     * 设置行为机密等级
     * 
     * @param confidentialityCode
     * @throws Hl7Exception
     */
    public void setConfidentialityCode(CE ce)
    {
        if (null != ce && ce.codeSystemEnName() != null && ce.codeName() != null)
        {
            setRimCoreActCdSets(ce, CONFIDENTIALITYCDSETCODE);
        }
        else
        {
            this.setConfidentialityCodeEtsId(ce.code().toString());
        }
    }


    /**
     * 获得设置行为机密等级
     */
    public CE getConfidentialityCode() throws Hl7Exception
    {
        if (this.getConfidentialityCodeEtsId().equals(CONFIDENTIALITYCDSETCODE.toString()))
        {
            for (RimCoreActCdSets actCdSets : this.getActCdSetsList())
            {
                if (this.getConfidentialityCodeEtsId().equals(actCdSets.getAttributeTypeCode()))
                {
                    return DataTypeUtil.getCE(actCdSets);
                }
            }
        }
        else
            return DataTypeUtil.getCE(this.getConfidentialityCodeEtsId());
        return null;
    }


    /**
     * 设置行为优先权
     */

    public void setPriorityCode(CE ce)
    {
        if (null != ce && ce.codeSystemEnName() != null && ce.codeName() != null)
        {
            setRimCoreActCdSets(ce, PRIORITYCDSETCODE);
        }
        else
        {
            this.setPriorityCodeEtsId(ce.code().toString());
        }
    }


    /**
     * 获取行为优先权
     */
    public CE getPriorityCode() throws Hl7Exception
    {
        if (this.getPriorityCodeEtsId().equals(PRIORITYCDSETCODE.toString()))
        {
            for (RimCoreActCdSets actCdSets : this.getActCdSetsList())
            {
                if (this.getPriorityCodeEtsId().equals(actCdSets.getAttributeTypeCode()))
                {
                    return DataTypeUtil.getCE(actCdSets);
                }
            }
        }
        else
            return DataTypeUtil.getCE(this.getPriorityCodeEtsId());
        return null;
    }


    /**
     * 设置行为原因代码
     */
    public void setReasonCode(SET_CE reasonCode)
    {
        CE ce = (CE) reasonCode.toSet().iterator().next();
        if (null != ce && ce.codeSystemEnName() != null && ce.codeName() != null)
        {
            setRimCoreActCdSets(ce, REASONCDSETCODE);
        }
        else
        {
            this.setReasonCodeEtsId(ce.code().toString());
        }
    }


    /**
     * 获取行为原因代码
     * 
     * @return SET_CE ReasonCode
     * @throws Hl7Exception
     */
    public CE getReasonCode() throws Hl7Exception
    {
        if (this.getReasonCodeEtsId().equals(REASONCDSETCODE.toString()))
        {
            for (RimCoreActCdSets actCdSets : this.getActCdSetsList())
            {
                if (this.getReasonCodeEtsId().equals(actCdSets.getAttributeTypeCode()))
                {
                    return DataTypeUtil.getCE(actCdSets);
                }
            }
        }
        else
            return DataTypeUtil.getCE(this.getReasonCodeEtsId());
        return null;
    }


    /**
     * 设置行为中text的语言种类属性
     */
    public void setLanguageCode(CE ce)
    {
        if (null != ce && ce.codeSystemEnName() != null && ce.codeName() != null)
        {
            setRimCoreActCdSets(ce, LANGUAGECDSETCODE);
        }
        else
        {
            this.setLanguageCodeEtsId(ce.code().toString());
        }
    }


    /**
     * 此方法重新实现 获取行为中text的语言种类属性
     */
    public CE getLanguageCode() throws Hl7Exception
    {
        if (this.getLanguageCodeEtsId().equals(LANGUAGECDSETCODE.toString()))
        {
            for (RimCoreActCdSets actCdSets : this.getActCdSetsList())
            {
                if (this.getLanguageCodeEtsId().equals(actCdSets.getAttributeTypeCode()))
                {
                    return DataTypeUtil.getCE(actCdSets);
                }
            }
        }
        else
            return DataTypeUtil.getCE(this.getLanguageCodeEtsId());
        return null;
    }


    /**
     * 设置行为级别代码属性
     */
    public void setLevelCode(CE ce)
    {
        if (null != ce && ce.codeSystemEnName() != null && ce.codeName() != null)
        {
            setRimCoreActCdSets(ce, LEVELCDSETCODE);
        }
        else
            this.setLevelCodeEtsId(ce.code().toString());
    }


    /**
     * 获取行为级别代码属性
     */
    public CE getLevelCode() throws Hl7Exception
    {
        if (this.getLevelCodeEtsId().equals(LEVELCDSETCODE.toString()))
        {
            for (RimCoreActCdSets actCdSets : this.getActCdSetsList())
            {
                if (this.getLevelCodeEtsId().equals(actCdSets.getAttributeTypeCode()))
                {
                    return DataTypeUtil.getCE(actCdSets);
                }
            }
        }
        else
            return DataTypeUtil.getCE(this.getLevelCodeEtsId());
        return null;
    }


    /**
     * 设置行为不确定因素。
     */
    public void setUncertaintyCode(CE ce)
    {
        if (null != ce && ce.codeSystemEnName() != null && ce.codeName() != null)
        {
            setRimCoreActCdSets(ce, UNCERTAINTYCDSETCODE);
        }
        else
        {
            this.setUncertaintyCodeEtsId(ce.code().toString());
        }
    }


    /**
     * 获取行为不确定因素。
     */
    public CE getUncertaintyCode() throws Hl7Exception
    {
        if (this.getUncertaintyCodeEtsId().equals(UNCERTAINTYCDSETCODE.toString()))
        {
            for (RimCoreActCdSets actCdSets : this.getActCdSetsList())
            {
                if (this.getUncertaintyCodeEtsId().equals(actCdSets.getAttributeTypeCode()))
                {
                    return DataTypeUtil.getCE(actCdSets);
                }
            }
        }
        else
            return DataTypeUtil.getCE(this.getUncertaintyCodeEtsId());
        return null;
    }


    /**
     * 设置动作cdSet集合
     * 
     * @param dicCode
     *            CE类型的术语值
     * @param attributeTypeCode
     *            确定cdSet的属性值
     */
    protected void setRimCoreActCdSets(CE dicCode, ActCdSetCode attributeTypeCode)
    {
        for (RimCoreActCdSets cdsets : getActCdSetsList())
        {
            if (cdsets.getAttributeTypeCode() != null && cdsets.getAttributeTypeCode().equals(attributeTypeCode.toString()))
            {
                // attributeTypeCode匹配直接更新
                convertRimCoreActCdSets(cdsets, dicCode);
                return;
            }
        }
        // 没有匹配新建
        RimCoreActCdSets rcrc = new RimCoreActCdSets();
        rcrc.setAttributeTypeCode(attributeTypeCode.toString());
        addActCdSets(convertRimCoreActCdSets(rcrc, dicCode));
    }


    protected RimCoreActCdSets getRimCoreActCdSets(ActCdSetCode attributeTypeCode)
    {
        if (attributeTypeCode == null)
        {
            return null;
        }
        for (RimCoreActCdSets cdsets : getActCdSetsList())
        {
            if (cdsets.getAttributeTypeCode() != null && cdsets.getAttributeTypeCode().equals(attributeTypeCode.toString()))
            {
                return cdsets;
            }
        }
        return null;
    }


    // 将CE的属性值赋给RimCoreRoleCdSets
    protected RimCoreActCdSets convertRimCoreActCdSets(RimCoreActCdSets cdsets, CE ce)
    {
        if (ce != null)
        {
            if (ce.codeSystemChName() != null)
            {
                cdsets.setCodingschemeChName(ce.codeSystemChName().isNull().booleanValue() ? null : ce.codeSystemChName().stringValue());
            }
            if (ce.codeSystemEnName() != null)
            {
                cdsets.setCodingschemeEnName(ce.codeSystemEnName().isNull().booleanValue() ? null : ce.codeSystemEnName().stringValue());
            }
            if (ce.codeName() != null)
            {
                cdsets.setConceptName(ce.codeName().isNull().booleanValue() ? null : ce.codeName().stringValue());
            }
            if (ce.codeSystemVersion() != null)
            {
                cdsets.setCodingschemeVersionName(ce.codeSystemVersion().isNull().booleanValue() ? null : ce.codeSystemVersion().stringValue());
            }
            if (ce.code() != null)
            {
                cdsets.setConceptCode(ce.code().isNull().booleanValue() ? null : ce.code().stringValue());
            }
            if (ce.codeSystem() != null)
            {
                cdsets.setCodingschemeOid(ce.codeSystem().isNull().booleanValue() ? null : ce.codeSystem().stringValue());
            }
        }
        return cdsets;
    }


    // 将II的属性值赋给RimCoreActIi
    protected RimCoreActIi convertRimCoreActIi(RimCoreActIi actii, II ii)
    {
        actii.setRootId(ii.root().stringValue());
        actii.setExtensionTxt(ii.extension().stringValue());
        actii.setIdentifierName(ii.identifierName().stringValue());
        if (ii.iiState() != null)
        {
            actii.setDisplayableFlag(ii.iiState().stringValue());
        }
        if (ii.iiSouce() != null)
        {
            actii.setIDSouce(ii.iiSouce().stringValue());
        }
        if (ii.clinicNo() != null)
        {
            actii.setClinicNo(ii.clinicNo().stringValue());
        }
        return actii;
    }


    /**
     * 根据动作拿实体
     * 
     * @param participationType
     *            角色参与的participation关系
     * @param roleCode
     *            实体扮演的角色code
     * @return Hl7Entity
     * @throws Hl7Exception
     */
    public Hl7Entity getHl7EntityByAct(CS participationType, CD roleCode) throws Hl7Exception
    {
        List<ActParticipation> parts = this.getParticipations();
        if (ListUtil.isNotEmpty(parts))
        {
            for (ActParticipation part : parts)
            {
                if (part.getTypecode().equals(participationType))
                {
                    Role drugRole = (Role) part.getRoleparticipation();
                    if (drugRole.getCode().code().toString().equals(roleCode.code().toString()))
                    {
                        Hl7Entity hl7Entity = drugRole.getPlayerEntity();
                        return hl7Entity;
                    }
                }
            }
        }
        return null;
    }


    /**
     * 根据participation的具体关系拿到参与到动作的具体Role
     * 
     * @param participationType
     *            角色参与到动作的关系
     * @return Role 参与到动作的具体角色
     * @throws Hl7Exception
     */
    public Role getRoleByAct(CS participationType) throws Hl7Exception
    {
        List<ActParticipation> parts = this.getParticipations();
        if (ListUtil.isNotEmpty(parts))
        {
            for (ActParticipation part : parts)
            {
                if (part.getTypecode().equals(participationType))
                {
                    Role role = (Role) part.getRoleparticipation();
                    return role;
                }
            }
        }
        return null;
    }

    // Act

    @Column(name = "MOOD_CODE", nullable = false)
    private String mood_Code;

    // derivationExpr
    @Column(name = "DERIVATION_EXPRESSION_TXT")
    private String derivationExpressionTxt;

    @Column(name = "TITLE_TXT")
    private String titleTxt;
    
    @Column(name = "TITLE_YWM")
    private String titleYwm;

    // effectiveTime
    @Column(name = "EFFECTIVE_DATE_GTS_TXT")
    private String effectiveDateGtsTxt;
    @Column(name = "EFFECTIVE_END_DATE_TS")
    private Timestamp effectiveEndDateTs;
    @Column(name = "EFFECTIVE_START_DATE_TS")
    private Timestamp effectiveStartDateTs;

    // availabilityTime
    @Column(name = "AVAILABLE_DATE_TXT")
    private String availableDateTxt;
    @Column(name = "AVAILABLITY_DATE_TS")
    private Timestamp availablityDateTs;
    @Column(name = "EXCUTE_TIME_TXT")
    private String excuteTimeTxt;

    @Column(name = "DURATION_TIME_VALUE")
    private String durationTimeTxt;
    @Column(name = "DURATION_TIME_UNIT")
    private String durationTimeUnit;

    @Column(name = "REPEAT_FLAG")
    private String repeatFlag;

    // repeatNumber
    @Column(name = "REP_NUM_HIGH_INCL_FLAG")
    private String repNumHighInclFlag;
    @Column(name = "REP_NUM_HIGH_VALUE_NUM")
    private Long repNumHighValueNum;
    @Column(name = "REP_NUM_IVL_VALUE_NUM")
    private Long repNumIvlValueNum;
    @Column(name = "REP_NUM_LOW_INCL_FLAG")
    private String repNumLowInclFlag;
    @Column(name = "REP_NUM_LOW_VALUE_NUM")
    private Long repNumLowValueNum;
    @Column(name = "FREQ_INTERVAL_VALUE")
    private String freqIntervalValue;
    @Column(name = "FREQ_INTERVAL_UNIT")
    private String freqIntervalUnit;

    @Column(name = "LEVEL_CODE_ETS_ID")
    private String levelCodeEtsId = LEVELCDSETCODE.toString();

    @Column(name = "NEGATION_FLAG")
    private String negationFlag;
    @Column(name = "INDEPENDENT_FLAG")
    private String independentFlag = "1";
    @Column(name = "INTERRUPTABLE_FLAG")
    private String interruptableFlag;
    @Column(name = "UNCERTAINTY_CODE_ETS_ID")
    private String uncertaintyCodeEtsId = UNCERTAINTYCDSETCODE.toString();
    @Column(name = "LANGUAGE_CODE_ETS_ID")
    private String languageCodeEtsId = LANGUAGECDSETCODE.toString();
    @Column(name = "CONFIDENTIALITY_CODE_ETS_ID")
    private String confidentialityCodeEtsId = CONFIDENTIALITYCDSETCODE.toString();
    @Column(name = "PRIORITY_CODE_ETS_ID")
    private String priorityCodeEtsId = PRIORITYCDSETCODE.toString();
    @Column(name = "REASON_CODE_ETS_ID")
    private String reasonCodeEtsId = REASONCDSETCODE.toString();


    /*
     * @Column(name = "CONFIDENTIALITY_CODE_ETS_ID") private String
     * confidentialityCodeEtsId = "confidentialityCode";
     * 
     * @Column(name = "PRIORITY_CODE_ETS_ID") private String priorityCodeEtsId =
     * "priorityCode";
     * 
     * @Column(name = "REASON_CODE_ETS_ID") private String reasonCodeEtsId =
     * "reasonCode";
     */

    // Act���Ĺ���
    private void setMoodCode(String mood_Code)
    {
        this.mood_Code = mood_Code;
    }


    protected String getMood_Code()
    {
        return mood_Code;
    }


    protected String getDerivationExpressionTxt()
    {
        return derivationExpressionTxt;
    }


    private void setDerivationExpressionTxt(String derivationExpressionTxt)
    {
        this.derivationExpressionTxt = derivationExpressionTxt;
    }


    protected String getTitleTxt()
    {
        return titleTxt;
    }


    private void setTitleTxt(String titleTxt)
    {
        this.titleTxt = titleTxt;
    }


    @SuppressWarnings("unused")
    protected String getEffectiveDateGtsTxt()
    {
        return effectiveDateGtsTxt;
    }


    private void setEffectiveDateGtsTxt(String effectiveDateGtsTxt)
    {
        this.effectiveDateGtsTxt = effectiveDateGtsTxt;
    }


    protected Timestamp getEffectiveEndDateTs()
    {
        return effectiveEndDateTs;
    }


    private void setEffectiveEndDateTs(Timestamp effectiveEndDateTs)
    {
        this.effectiveEndDateTs = effectiveEndDateTs;
    }


    protected Timestamp getEffectiveStartDateTs()
    {
        return effectiveStartDateTs;
    }


    private void setEffectiveStartDateTs(Timestamp effectiveStartDateTs)
    {
        this.effectiveStartDateTs = effectiveStartDateTs;
    }


    protected String getActivityDateGtsTxt()
    {
        return activityDateGtsTxt;
    }


    private void setActivityDateGtsTxt(String activityDateGtsTxt)
    {
        this.activityDateGtsTxt = activityDateGtsTxt;
    }


    protected Timestamp getActivityEndDateTs()
    {
        return activityEndDateTs;
    }


    private void setActivityEndDateTs(Timestamp activityEndDateTs)
    {
        this.activityEndDateTs = activityEndDateTs;
    }


    protected Timestamp getActivityStartDateTs()
    {
        return activityStartDateTs;
    }


    private void setActivityStartDateTs(Timestamp activityStartDateTs)
    {
        this.activityStartDateTs = activityStartDateTs;
    }


    protected String getAvailableDateTxt()
    {
        return availableDateTxt;
    }


    private void setAvailableDateTxt(String availableDateTxt)
    {
        this.availableDateTxt = availableDateTxt;
    }


    protected Timestamp getAvailablityDateTs()
    {
        return availablityDateTs;
    }


    private void setAvailablityDateTs(Timestamp availablityDateTs)
    {
        this.availablityDateTs = availablityDateTs;
    }


    protected String getExcuteTimeTxt()
    {
        return excuteTimeTxt;
    }


    private void setExcuteTimeTxt(String excuteTimeTxt)
    {
        this.excuteTimeTxt = excuteTimeTxt;
    }


    protected String getDurationTimeTxt()
    {
        return durationTimeTxt;
    }


    private void setDurationTimeTxt(String durationTimeTxt)
    {
        this.durationTimeTxt = durationTimeTxt;
    }


    protected String getDurationTimeUnit()
    {
        return durationTimeUnit;
    }


    private void setDurationTimeUnit(String durationTimeUnit)
    {
        this.durationTimeUnit = durationTimeUnit;
    }


    protected String getRepeatFlag()
    {
        return repeatFlag;
    }


    private void setRepeatFlag(String repeatFlag)
    {
        this.repeatFlag = repeatFlag;
    }


    protected String getRepNumHighInclFlag()
    {
        return repNumHighInclFlag;
    }


    private void setRepNumHighInclFlag(String repNumHighInclFlag)
    {
        this.repNumHighInclFlag = repNumHighInclFlag;
    }


    protected Long getRepNumHighValueNum()
    {
        return repNumHighValueNum;
    }


    private void setRepNumHighValueNum(Long repNumHighValueNum)
    {
        this.repNumHighValueNum = repNumHighValueNum;
    }


    protected Long getRepNumIvlValueNum()
    {
        return repNumIvlValueNum;
    }


    private void setRepNumIvlValueNum(Long repNumIvlValueNum)
    {
        this.repNumIvlValueNum = repNumIvlValueNum;
    }


    protected String getRepNumLowInclFlag()
    {
        return repNumLowInclFlag;
    }


    private void setRepNumLowInclFlag(String repNumLowInclFlag)
    {
        this.repNumLowInclFlag = repNumLowInclFlag;
    }


    protected Long getRepNumLowValueNum()
    {
        return repNumLowValueNum;
    }


    private void setRepNumLowValueNum(Long repNumLowValueNum)
    {
        this.repNumLowValueNum = repNumLowValueNum;
    }


    protected String getFreqIntervalValue()
    {
        return freqIntervalValue;
    }


    private void setFreqIntervalValue(String freqIntervalValue)
    {
        this.freqIntervalValue = freqIntervalValue;
    }


    protected String getFreqIntervalUnit()
    {
        return freqIntervalUnit;
    }


    private void setFreqIntervalUnit(String freqIntervalUnit)
    {
        this.freqIntervalUnit = freqIntervalUnit;
    }


    protected String getLevelCodeEtsId()
    {
        return levelCodeEtsId;
    }


    private void setLevelCodeEtsId(String levelCodeEtsId)
    {
        this.levelCodeEtsId = levelCodeEtsId;
    }


    protected String getNegationFlag()
    {
        return negationFlag;
    }


    private void setNegationFlag(String negationFlag)
    {
        this.negationFlag = negationFlag;
    }


    protected String getIndependentFlag()
    {
        return independentFlag;
    }


    private void setIndependentFlag(String independentFlag)
    {
        this.independentFlag = independentFlag;
    }


    protected String getInterruptableFlag()
    {
        return interruptableFlag;
    }


    private void setInterruptableFlag(String interruptableFlag)
    {
        this.interruptableFlag = interruptableFlag;
    }


    protected String getLanguageCodeEtsId()
    {
        return languageCodeEtsId;
    }


    private void setLanguageCodeEtsId(String languageCodeEtsId)
    {
        this.languageCodeEtsId = languageCodeEtsId;
    }


    protected String getUncertaintyCodeEtsId()
    {
        return uncertaintyCodeEtsId;
    }


    private void setUncertaintyCodeEtsId(String uncertaintyCodeEtsId)
    {
        this.uncertaintyCodeEtsId = uncertaintyCodeEtsId;
    }


    protected String getConfidentialityCodeEtsId()
    {
        return confidentialityCodeEtsId;
    }


    private void setConfidentialityCodeEtsId(String confidentialityCodeEtsId)
    {
        this.confidentialityCodeEtsId = confidentialityCodeEtsId;
    }


    protected String getPriorityCodeEtsId()
    {
        return priorityCodeEtsId;
    }


    private void setPriorityCodeEtsId(String priorityCodeEtsId)
    {
        this.priorityCodeEtsId = priorityCodeEtsId;
    }


    protected String getReasonCodeEtsId()
    {
        return reasonCodeEtsId;
    }


    private void setReasonCodeEtsId(String reasonCodeEtsId)
    {
        this.reasonCodeEtsId = reasonCodeEtsId;
    }


    /*
     * private void setConfidentialityCodeEtsId(String confidentialityCodeEtsId)
     * { this.confidentialityCodeEtsId = confidentialityCodeEtsId; }
     * 
     * private String getConfidentialityCodeEtsId() { return
     * confidentialityCodeEtsId; }
     * 
     * private void setPriorityCodeEtsId(String priorityCodeEtsId) {
     * this.priorityCodeEtsId = priorityCodeEtsId; }
     * 
     * private String getPriorityCodeEtsId() { return priorityCodeEtsId; }
     * 
     * private void setReasonCodeEtsId(String reasonCodeEtsId) {
     * this.reasonCodeEtsId = reasonCodeEtsId; }
     * 
     * private String getReasonCodeEtsId() { return reasonCodeEtsId; }
     */

    protected String getTitleYwm()
    {
        return titleYwm;
    }


     private void setTitleYwm(String titleYwm)
    {
        this.titleYwm = titleYwm;
    }


    public ActParticipation addControlActPrtcptns(ActParticipation prtcptns)
    {
        getControlActPrtcptnsList().add(prtcptns);
        prtcptns.setControlAct(this);
        return prtcptns;
    }


    public ActParticipation removeControlActPrtcptns(ActParticipation prtcptns)
    {
        getControlActPrtcptnsList().remove(prtcptns);
        prtcptns.setControlAct(null);
        return prtcptns;
    }


    public ActRelationship addSourceAct(ActRelationship actRelations)
    {
        ((List<ActRelationship>) getSourceActRelationsList()).add(actRelations);
        actRelations.setSourceAct(this);
        return actRelations;
    }


    public RimCoreActRelations removeSourceAct(RimCoreActRelations actRelations)
    {
        getSourceActRelationsList().remove(actRelations);
        actRelations.setSourceAct(null);
        return actRelations;
    }


    @SuppressWarnings("unchecked")
    public ActParticipation addPrtcptnsAct(ActParticipation prtcptns)
    {
        ((List<ActParticipation>) getPrtcptnsActList()).add(prtcptns);
        prtcptns.setParticipationAct(this);
        return prtcptns;
    }


    @SuppressWarnings("unchecked")
    public List<ActRelationship> getSourceActRelationship()
    {
        return (List<ActRelationship>) getSourceActRelationsList();
    }


    @SuppressWarnings("unchecked")
    public List<ActRelationship> getTargetActRelationship()
    {
        return (List<ActRelationship>) getTargetActRelationsList();
    }


    public RimCoreActPrtcptns removePrtcptnsAct(RimCoreActPrtcptns prtcptns)
    {
        getPrtcptnsActList().remove(prtcptns);
        prtcptns.setParticipationAct(null);
        return prtcptns;
    }


    @SuppressWarnings("unchecked")
    public ActRelationship addTargetAct(ActRelationship actRelations)
    {
        ((List<ActRelationship>) getTargetActRelationsList()).add(actRelations);
        actRelations.setTargetAct(this);
        return actRelations;
    }


    public RimCoreActRelations removeTargetAct(RimCoreActRelations actRelations)
    {
        getTargetActRelationsList().remove(actRelations);
        actRelations.setTargetAct(null);
        return actRelations;
    }


    protected void converRimCoreEds(RimCoreEds rimCoreEd, ED ed)
    {
        if (rimCoreEd == null)
        {
            rimCoreEd = new RimCoreEds();
        }
        rimCoreEd.setEdBlob(ed.integrityCheck().byteArray()); // 二进制文件
        rimCoreEd.setEdClob(ed.literal().toString().toCharArray()); // 大文本
        rimCoreEd.setMediaTypeCode(ed.mediaType().toString());
        rimCoreEd.setCharacterSetCode(ed.charset().toString());
        rimCoreEd.setLanguageCode(ed.language().toString());
        rimCoreEd.setCompressionCode(ed.compression().toString());
        rimCoreEd.setRefTelAddressTxt(ed.reference().address().toString());
        rimCoreEd.setRefTelSchemeCode(ed.reference().scheme().toString());
        if (null != ed.reference().useablePeriod().hull().low())
        {
            rimCoreEd.setRefTelStartDateTs(new Timestamp(ed.reference().useablePeriod().hull().low().toDate().getTime()));
        }
        if (null != ed.reference().useablePeriod().hull().high())
        {
            rimCoreEd.setRefTelEndDateTs(new Timestamp(ed.reference().useablePeriod().hull().high().toDate().getTime()));
        }
        rimCoreEd.setRefTelGtsTxt(ed.reference().useablePeriod().literal().toString());
        rimCoreEd.setEdRefTelUses(ed.reference().use().toSet());
        rimCoreEd.setIntegrityCheckAlgCode(ed.integrityCheckAlgorithm().toString());
        /*
         * if (!ed.integrityCheck().isNull().booleanValue()) { //次属性有问题，暂时屏蔽
         * rimCoreEd.setIntegrityCheckTxt(ed.integrityCheck().stringValue()); }
         */
    }

}
